package com.jetpack.mvvm.lib.base.interceptor

import android.content.Context
import android.util.Log
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.jetpack.mvvm.lib.base.RouterConstant
import com.jetpack.mvvm.lib.base.utils.AppCommon

@Interceptor(name = "check user login", priority = 1)
class LoginInterceptor : IInterceptor{
    companion object {
        private const val TAG = "LoginInterceptor"
    }
    private var pageList = mutableListOf<String>()

    override fun init(context: Context?) {
//        pageList.add(RouterConstant.LoginRegister.PAGE_REGISTER)
    }

    override fun process(postcard: Postcard, callback: InterceptorCallback) {
        if (pageList.contains(postcard.path)) {
            if (AppCommon.isUserLogin) { // 如果已经登录了，则默认不做任何处理
                callback.onContinue(postcard)
            } else { // 未登录，拦截
                callback.onInterrupt(null)
            }
        } else {
            callback.onContinue(postcard)
        }
    }

}